package com.cfgj.web;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@RequestMapping("/admin")
@Controller
public class LoginController {
    @RequestMapping("/login")
    public String login(){
        return "admin/login";
    }

    @RequestMapping("/index")
    public String index(HttpSession session){
        UserDetails userDetails=null;
        try {
            userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        }
        catch (Exception e){
            return "0";
        }
        String name=userDetails.getUsername();
        session.setAttribute("adminUser",name);
        return "admin/index";
    }





}
